package com.hecore.lagou.mr.partition;

import com.hecore.lagou.mr.entity.PartitionBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;


/**
 * @Author: hecore
 * @Date: 2020/10/18 21:28
 * @Description:
 */

public class CustomPartitioner extends Partitioner<Text, PartitionBean> {

    /**
     * 重写获取分区规则
     *      通过前后缀处理
     * @param text
     * @param partitionBean
     * @param numPartitions
     * @return
     */
    @Override
    public int getPartition(Text text, PartitionBean partitionBean, int numPartitions) {
        int partition=0;
        final String appkey = text.toString();
        if(appkey.equals("kar")){
            partition=1;
        }else if(appkey.equals("pandora")){
            partition=2;
        }else{
            partition=0;
        }
        return partition;
    }
}
